const Router = require('koa-router');
const router = new Router();
const {db, Op, QueryTypes} = require("../../models/db");
// 手机 收款明细
router.post('/ldsk/skDetail', async ctx => {
    let buId = ctx.request.body.buId
    let doId = ctx.user.id
    let tid = ctx.user.tenantId
    let sql = `
        select a.id appSkId,a.billId,a.leftAmount,b.billNo srcBillNo,b.transTypeName srcTransTypeName,
               b.salesId,c.name salesName  ,b.buId, co.name buName ,b.billDate srcBillDate ,
               a.leftAmount as nowCheck,0 as yhAmount 
        from app_sk a inner join invoice b on a.billId=b.id 
        and a.tenantId=${tid} and a.doId=${doId} and a.billState=N'收款中' and b.buId=${buId} 
            inner join contact co on b.buId=co.id 
        left join admin c on b.salesId=c.id 
        order by b.transType
     `
    let list = await db.query(sql, {type: QueryTypes.SELECT})
    return ctx.suc('', list)
})






module.exports = router;